package com.prd.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.prd.config.LoginInterceptor;
import com.prd.mapper.EntNarrationInterviewMapper;
import com.prd.model.EntNarration;
import com.prd.model.EntNarrationInterview;
import com.prd.model.LoginUser;
import com.prd.service.EntNarrationInterviewService;
import com.prd.service.EntNarrationService;
import com.prd.util.UserInfoUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EntNarrationInterviewServiceImpl extends ServiceImpl<EntNarrationInterviewMapper, EntNarrationInterview> implements EntNarrationInterviewService {

    @Autowired
    private EntNarrationInterviewMapper entNarrationInterviewMapper;

    @Autowired
    private EntNarrationService entNarrationService;

    @Override
    public int insertInfo(EntNarrationInterview entNarrationInterview) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), true), entNarrationInterview);
        return entNarrationInterviewMapper.insert(entNarrationInterview);
    }

    @Override
    public int updateInfo(EntNarrationInterview entNarrationInterview) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), false), entNarrationInterview);
        return entNarrationInterviewMapper.updateById(entNarrationInterview);
    }

    @Override
    public int insertInterview(EntNarrationInterview entNarrationInterview) {
        EntNarration entNarration = entNarrationService.getById(entNarrationInterview.getNarrationId());
        if (entNarration == null) {
            throw new RuntimeException("记录没有找到！");
        }
        entNarration.setStatus(2);
        entNarrationService.updateInfo(entNarration);
        return insertInfo(entNarrationInterview);
    }
}
